package com.gxa.modules.service.impl;

import com.gxa.common.constants.Constants;
import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.R;
import com.gxa.modules.mapper.CustComplianMapper;
import com.gxa.modules.pojo.CustComplian;
import com.gxa.modules.service.Cust_ComplianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Cust_ComplianServiceimpl implements Cust_ComplianService {
    @Autowired
    private CustComplianMapper custcomplianMapper;
    JsonResult jsonResult = new JsonResult();
    R r = new R();
    /**/

    /**
     * 分页查询客户投诉列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public JsonResult findCustComplian(Integer currentPage, Integer pageSize) {
        int count = custcomplianMapper.findCountCust(Constants.STATUS_UNDEL);
        Integer start = (currentPage-1)*pageSize;
        Integer off = pageSize;
        List<Map> result = custcomplianMapper.findCustComplian(start, off, Constants.STATUS_UNDEL);        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        jsonResult.setCount(count);
        jsonResult.setData(result);
        return jsonResult;

    }

    /**
     * 增加客户投诉接口
     * @param custComplian
     * @return
     */
    @Override
    public R addCust_Complian(CustComplian custComplian) {
        int result = custcomplianMapper.addCustcomplian(custComplian);
        if (result>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }

    /**
     * 删除客户投诉
     * @param id
     * @return
     */
    @Override
    public R deleteCust_Complian(Integer id) {
        int result = custcomplianMapper.deleteCustcomplian(id, Constants.STATUS_DEL);
        if (result>0){
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }

    /**
     *批量删除客户投诉
     * @param ids
     * @return
     */
    @Override
    public R deleteCust_ComplianList(int[] ids) {
        if (ids.length>0){
            int result = custcomplianMapper.deleteCustcomplianList(ids, Constants.STATUS_DEL);
        }
            r.setCode(200);
            r.setMsg("批量删除成功");
            return r;
    }

    /**
     * 修改客户投诉
     * @param custComplian
     * @return
     */
    @Override
    public R updateCust_Complian(CustComplian custComplian) {
        int i = custcomplianMapper.updateCustcomplian(custComplian);
        if (i>0){
            r.setCode(200);
            r.setMsg("修改成功");
        }
        return r;
    }

    /**
     * 查看客户投诉显示接口
     * @param id
     * @return
     */
    @Override
    public JsonResult seeCust_Complian(Integer id) {
        List<CustComplian> custComplians = custcomplianMapper.seeCustcomplian(id);
        jsonResult.setMsg("查询成功");
        jsonResult.setData(custComplians);
        return jsonResult;
    }

    /**
     * 添加处理
     * @param id
     * @param deal_note
     * @param deal_time
     * @return
     */
    @Override
    public R dealCust_Complian(Integer id, String deal_note, String deal_time) {
        int i = custcomplianMapper.dealCustcomplian(id, deal_note,deal_time);
        if (i>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }

    /**
     * 添加完结
     * @param id
     * @param end_note
     * @param end_time
     * @return
     */
    @Override
    public R endCust_Complian(Integer id, String end_note, String end_time) {
        int i = custcomplianMapper.endCustcomplian(id, end_note, end_time);
        if (i>0){
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;

    }

    /**
     * 条件搜索客户投诉
     * @param customer_name
     * @param waybill_number
     * @param complian_type
     * @param operator_time
     * @return
     */
    @Override
    public JsonResult searchCust_Complian(String customer_name, String waybill_number, Integer complian_type, String operator_time) {
        List<Map> maps = custcomplianMapper.searchCustcomplian(customer_name, waybill_number, complian_type, operator_time, Constants.STATUS_UNDEL);
        jsonResult.setMsg("查询成功");
        jsonResult.setData(maps);
        return jsonResult;
    }


}
